<template>
  <div>
    <h3 style="text-align: center">ProtocolChart</h3>
    <div id="ProtocolChart" style="width:90%;height:300px;"></div>
  </div>
</template>

<script>
export default {
  name: 'ProtocolChart',
  data () {
    return {
      myChart: null,
      protocolChartData:null,
      protocolTypeName:null,
    }
  },
  created() {
    this.$Pubsub.subscribe("protocolChartData",(msgName,msg)=>{
      this.protocolChartData = msg[0]
      this.protocolTypeName = msg[1]
      this.chartInit()
    })
  },
  mounted () {
    this.chartInit()
  },
  methods: {
    chartInit () {
      if (this.myChart !== null) {
        this.myChart.dispose()
      }
      this.myChart = this.$echarts.init(document.getElementById('ProtocolChart'))
      let option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          orient: 'horizontal',
          top: '0%',
          data: this.protocolTypeName
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: '50%',
            center: ['50%', '50%'],
            data: this.protocolChartData,
            itemStyle: {
              emphasis: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      }
      this.myChart.setOption(option)
    }
  }
}
</script>

<style scoped>

</style>
